﻿package com.ufenlei.LTS {
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	
	public class Slide extends Input{
		protected var handle:MovieClip;
		protected var path:MovieClip;
		private var _pecentage:Number;
		private var _low:Number = 1.0;
		private var _high:Number = 0;
		public function Slide(defaultPosition:Number = 0, lowPosition:Number = 0, highPosition:Number = 1.0, isLocked:Boolean = false){
			_pecentage = defaultPosition;
			_low = lowPosition;
			_high = highPosition;
			super(false,isLocked);
		}
		public function set pecentage(pecent:Number):void{
			_pecentage = Math.max(0 , Math.min(pecent,1));
			position = _zero + _length * _pecentage;
			dispatchProgEvent();
		}
		public function get pecentage():Number{
			return _pecentage;
		}
		protected function initSlide(sHandle:MovieClip,sPath:MovieClip):void{
			handle = sHandle;
			path = sPath;
			addViewClip(sHandle);
			addEventListenerOn(handle);
			handle.addEventListener(MouseEvent.MOUSE_DOWN, handleOnMouseDown);
		}
		private function handleOnMouseDown(evt:MouseEvent):void{
			handle.startDrag( false,path.getRect(this) );
			this.addEventListener(Event.ENTER_FRAME, onDragEE);
			(root as MovieClip).addEventListener(MouseEvent.MOUSE_UP , onHandleMouseUp);
		}
		private function onHandleMouseUp(evt:MouseEvent):void{
			handle.stopDrag();
			this.removeEventListener(Event.ENTER_FRAME,onDragEE);
			(root as MovieClip).removeEventListener(MouseEvent.MOUSE_UP , onHandleMouseUp);
		}
		private function onDragEE(evt:Event):void{
			dispatchProgEvent();
		}
		protected function dispatchProgEvent():void{
			var prog:ProgressEvent = new ProgressEvent(Input.CHANGE,false,false,position - _zero, _length);
			this.dispatchEvent(prog);
		}
		protected function updateHandle():void{
			this.position = position;
		}
		public function get position():int{
			return 0;
			//重载这个方法
		}
		public function set position(po:int):void{
			//重载这个方法
		}
		protected function get _zero():int{
			return 0;
		}
		protected function get _length():int{
			return 0;
		}
	}
}